home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / protect-your-privacy / p.g.p. / pgpamiga / contrib / ced / encryptpgp.ced < prev    next >
Text File  |  1996-02-26  |  7KB  |  250 lines

  1. /*******************************************************************/
  2. /*                                                                 */
  3. /* EncryptPGP.ced - ARexx macro for use with Cygnus Editor and PGP */
  4. /*                                                                 */
  5. /* Mark a block of text you want to be encrypted using PGP, then   */
  6. /* run this macro to encrypt it wit someone's public key. It works */
  7. /* similar to builtin rot13 command. (Only MUCH slower).           */
  8. /* This macro was tested to work with Cygnus Editor 2.0 to 3.5.    */
  9. /*                                                                 */
  10. /* This code is in Public Domain under GNU General Public License  */
  11. /*                                                                 */
  12. /* author: Janusz A. Urbanowicz <alex@vm.cc.uni,torun.pl>          */
  13. /*                                                                 */
  14. /* See CEDPGP.guide for more info                                  */
  15. /*                                                                 */
  16. /*******************************************************************/
  17.  
  18. /*
  19.  *                $VER: EncryptPGP.ced 1.3 (30.10.1994)
  20.  */
  21.  
  22. /* This macro uses PGPUSER environmental variable to determine */
  23. /* which private key should be used to sign the text. If there is no */
  24. /* PGPUSER variable it uses the default key to sign (if needed) */
  25.  
  26. Trace Off
  27.  
  28. Options Results
  29.  
  30. lf = '0A'X
  31. tempfile = 'T:ced$pgp.tmp'
  32. cmdn = '-ea'
  33. cmdf = '<'||tempfile||' -o '||tempfile||'.asc -fea'
  34. pgpt = 0 /* pgp 'type' 0 = 2.3a, 1 = 2.3a.?, 2 = 2.6<ui> */
  35. scratch = 0
  36. ID = ''
  37.  
  38. scrname = 'CygnusEdScreen'
  39. scrnum = 1
  40. portname = 'rexx_ced'
  41. portnum = 0
  42.  
  43. /*                               main()                           */
  44.  
  45. status portnumber
  46. portnum = result
  47. if (portnum ~= 0)&(portnum ~== 'RESULT') Then
  48. Do
  49.         scrnum = scrnum + portnum
  50.         portname = portname||portnum
  51. End
  52.  
  53. scrname = scrname||scrnum
  54.  
  55. Call Close 'STDOUT'             /* Thanx for that goes to Rick Younie*/
  56. Call Close 'STDIN'
  57. Call Open 'STDOUT','CON:16/24/620/130/PGPAmiga Output/CLOSE/WAIT/SCREEN'||scrname
  58. Call Pragma '*','STDOUT'
  59. Call Open 'STDIN','*'
  60.  
  61.  
  62. Call checkf
  63. pgpt = result
  64. If pgpt > 0 Then
  65. Do
  66.         cmd = cmdf
  67.         cmdline = ''
  68. End
  69. Else
  70. Do
  71.         cmd = cmdn
  72.         cmdline = tempfile||' '
  73. End
  74.  
  75. Address Value portname
  76. getstring '" "  "Please enter recipient`s userid:"'
  77. ID = result
  78. ID = Strip(ID,'B')
  79.  
  80. Address Command
  81. 'GetEnv >PIPE:PGPUSER PGPUSER'
  82. If rc = 0 Then
  83. Do
  84.         If ~Open('user','PIPE:PGPUSER','R') Then
  85.         Do
  86.                 Address value portname
  87.                 Okay1 "Problem while opening PGPUSER environmental variable"||lf||,
  88.                 "Fatal error, macro execution aborted."
  89.                 Call quit
  90.         End
  91.         Else
  92.         Do
  93.                 userid = ReadLN('user')
  94.                 If ~Close('user') Then Nop
  95.                 cmdline = cmdline||ID||' -u '||'"'||userid||'"'
  96.         End
  97. End
  98. Else cmdline = cmdline||ID
  99.  
  100. Address Value portname
  101. If pgpt = 1 Then /* is PGP26_IMPERSONATE option avaliable ? */
  102. Do
  103.         okay2 "Do you want the encrypted packet to be"||lf,
  104.                 "in PGP 2.6 format ?"
  105.         If result = 1 Then
  106.         Do
  107.                 okay1 "WARNING: Packet created with this"||lf,
  108.                 ||"option set cannot be processed"||lf,
  109.                 ||"using 'standard' PGP 2.3a."||lf||lf,
  110.                 ||"You SHOULD NOT use this option"
  111.                 okay2 "Are you sure you want to use"||lf,
  112.                         ||"this option ?"
  113.                 If result = 1 Then cmdline = cmdline||' +PGP26_IMPERSONATE=on'
  114.         End
  115. End
  116. Else cmdline = cmdline||' +batchmode=on'
  117.  
  118. okay2 "Do you want to sign the text with"||lf||" your private key ??"
  119. If result = 1 Then
  120. Do
  121.         If cmd = cmdn Then Call ask
  122.         cmd = cmd||'st '
  123. End
  124. Else cmd = cmd||'t '
  125.  
  126. cmdline = cmd||cmdline
  127.  
  128. cut block
  129. If result = 1 Then Call encrypt
  130. Else
  131. Do
  132.         okay2 "No area selected."||lf||"Encrypt whole file ?"
  133.         If result = 1 Then
  134.         Do
  135.                 'beg of file'
  136.                 'mark block'
  137.                 'end of file'
  138.                 'cut block'
  139.                 Call encrypt
  140.         End
  141. End
  142. Call quit
  143.  
  144. encrypt:
  145. Do
  146.         menu 0 6 0 tempfile /* save block to file */
  147.         Address Command
  148.         'PGP '||cmdline
  149.         If ~Exists(tempfile||'.asc') Then Call wrongpass
  150.         Else
  151.         Do
  152. /* We check if the output file length is 0 what happens if PGP was in -f mode and passphrase was wrong */
  153.                 If Open('outf',tempfile||'.asc','R') Then
  154.                 Do
  155.                         If Seek('outf',100,'Begin') = 0 Then Call wrongpass
  156.                         Else
  157.                         Do
  158.                                 Address value portname
  159.                                 include file tempfile||'.asc'
  160.                                 status 21
  161.                         End
  162.                 End
  163.         End
  164. End
  165. Return
  166.  
  167. wrongpass:
  168. Address value portname
  169. undo
  170. okay1 "Wrong passphrase !"
  171.  
  172. quit:
  173. Address Command
  174. If Exists(tempfile||'.info') Then 'Delete '||tempfile||'.info QUIET'
  175. If Exists(tempfile||'.asc') Then 'Delete '||tempfile||'.asc QUIET'
  176. If Exists(tempfile) Then 'Delete '||tempfile||' QUIET'
  177. If scratch == 1 Then 'Delete env:PGPPASS QUIET'
  178. If ~Close('STDOUT') Then Nop
  179. Exit 0
  180.  
  181. ask: Procedure Expose scratch lf portname
  182. Address Command
  183. 'GetEnv >NIL: PGPPASS'
  184. If rc ~= 0 Then
  185. Do
  186.         Address value portname
  187.         okay2 "Your passphrase is not set in PGPPASS variable."||lf||,
  188.         "It must be set temporarily for running PGP".||lf||,
  189.         "Should it be deleted (for higher security) after use ??"
  190.         If result = 1 then scratch = 1
  191.         else scratch = 0
  192.         okay1 'WARNING: Your passphrase will be visible when you type it in.'
  193.         getstring "'  '  'Please enter passphrase.'"
  194.         pgppass = result
  195.         pgppass = Strip(pgppass,'T')
  196.         Address Command
  197.         'SetEnv PGPPASS '||'"'||pgppass||'"'
  198. End
  199. Return
  200.  
  201. checkf: Procedure
  202. Address Command
  203. Call getpath
  204. path = result
  205. If path = "" Then Return 0
  206. Else
  207. Do
  208.         'Version >PIPE:PGPVERSION '||path
  209.         If Open('pvers','PIPE:PGPVERSION','R') Then
  210.         Do
  211.                 verstring = ReadLN('pvers')
  212.                 If Close('pvers') Then Nop
  213.         End
  214.         Parse Var verstring . version
  215.         Select
  216.                 When version = '2.6ui' Then Return 2
  217.                 When version = '2.3a.5' Then Return 1
  218.                 When version = '2.3a.4' Then Return 1
  219.                 When version = '2.3a.3' Then Return 1
  220.                 Otherwise Return 0
  221.         End
  222. End
  223.  
  224. getpath: procedure
  225. 'Which >PIPE:PGPPATH PGP'
  226. If rc = 0 Then
  227. Do
  228.         If Open('ppath','PIPE:PGPPATH','R') Then
  229.         Do
  230.                 path = ReadLN('ppath')
  231.                 If ~Close('ppath') Then Nop
  232.                 Return path
  233.         End
  234. End
  235. Else
  236. Do
  237.         'GetEnv >PIPE:PGPPATH PGPPATH'
  238.         If rc = 0 Then
  239.         Do
  240.                 If Open('ppath','PIPE:PGPPATH','R') Then
  241.                 Do
  242.                         path = ReadLN('ppath')
  243.                         If ~Close('ppath') Then Nop
  244.                         path = path||'/PGP'
  245.                         Return path
  246.                 End
  247.                 Else Return ""
  248.         End
  249. End
  250.